home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / print / tspool2.lha / TSPOOL / SOURCE / tspool.c < prev   
Encoding:
C/C++ Source or Header  |  1994-10-21  |  6.2 KB  |  206 lines

  1. /* ----------------------------------------------------------------- */
  2. /*      TSpool Version 1.0 (C) Fourth Level Developments 1994        */
  3. /* ----------------------------------------------------------------- */
  4.  
  5.  
  6. /*
  7.  
  8. TSpool  is  written  by  T.Southwell  and is (C) Fourth Level Developements
  9. 1994.   You  may freely distribute these programs and documentation as long
  10. as you do not make a charge of any more than a reasonable copying fee. If 
  11. you wish to revise or update the software then please do but you must then
  12. send a copy of the new version and source code to Fourth Level Developments.
  13. Fourth Level Developments will be willing to have this software incorporated in other software packages but
  14. in other programmes but you must first put your suggestions to us and obtain
  15. written permission before you start work on it.
  16.  
  17.  
  18. This is the main print spooler, its a standard AmigaDos filesystem handler
  19. which supports only the basic (Write/FindOutput/End) Packets. It saves
  20. the data to spool files in spool: and updates the list in t:
  21.  
  22. Email: dev@flevel.demon.co.uk
  23.  
  24. */
  25.  
  26. #include <stdio.h>
  27.  
  28. #ifndef EXEC_EXECBASE_H
  29. #include <exec/execbase.h>
  30. #endif
  31.  
  32. #ifndef EXEC_ALERTS_H
  33. #include <exec/alerts.h>
  34. #endif
  35.  
  36. #ifndef RESOURCES_MISC_H
  37. #include <resources/misc.h>
  38. #endif
  39.  
  40. #ifndef HARDWARE_CIA_H
  41. #include <hardware/cia.h>
  42. #endif
  43.  
  44. #ifndef DOS_FILEHANDLER_H
  45. #include <dos/filehandler.h>
  46. #endif
  47.  
  48. #ifndef CLIB_EXEC_PROTOS_H
  49. #include <clib/exec_protos.h>
  50. #endif
  51.  
  52. #ifndef CLIB_DOS_PROTOS_H
  53. #include <clib/dos_protos.h>
  54. #endif
  55.  
  56. #ifndef CLIB_MISC_PROTOS_H
  57. #include <clib/misc_protos.h>
  58. #endif
  59.  
  60. #include <pragmas/exec_pragmas.h>
  61. #include <pragmas/dos_pragmas.h>
  62. #include <pragmas/misc_pragmas.h>
  63.  
  64. /***********************************************/
  65. void __saveds FastPAR(void)
  66.  
  67. {
  68.    struct ExecBase *SysBase;
  69.    struct DosLibrary *DOSBase;
  70.    struct DosPacket *Packet;
  71.    struct DeviceNode *DeviceNode;
  72.    struct Process *MyProcess;
  73.    long filecnt=0;
  74.    BPTR filehan=0;
  75.    BPTR listhan=0;
  76.    long filesize=0;
  77.    char filename[20];
  78.    int startedt=0;
  79.  
  80.    SysBase=(struct ExecBase *)*(ULONG *)4;
  81.    if (!(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)))
  82.       {
  83.          Alert(AT_DeadEnd | AG_OpenLib | AO_DOSLib);
  84.       }
  85.    MyProcess=(struct Process *)(SysBase->ThisTask);
  86.  
  87.    Packet=WaitPkt();
  88.    DeviceNode=BADDR(Packet->dp_Arg3);
  89.    DeviceNode->dn_Task=&MyProcess->pr_MsgPort;
  90.    ReplyPkt(Packet,DOSTRUE,0L);
  91.  
  92.    while (TRUE)
  93.       {
  94.          Packet=WaitPkt();
  95.          switch(Packet->dp_Type)
  96.             {
  97.                case ACTION_FINDINPUT:
  98.                case ACTION_FINDOUTPUT:
  99.                case ACTION_FINDUPDATE:    
  100.                
  101.                     if (filehan)
  102.                        {
  103.                        ReplyPkt(Packet,DOSFALSE,0L);
  104.                        break;
  105.                        }
  106.                     
  107.                     if (startedt==0)
  108.                        {
  109.                        Execute("run spoolit",0L,0L);
  110.                        startedt=1;
  111.                        }
  112.                
  113.                
  114.                     filecnt++;
  115.                     sprintf(filename,"spool:spool%ld",filecnt);
  116.                     filesize=0;
  117.                     filehan=(BPTR)Open(filename,MODE_NEWFILE);
  118.                     if (filehan)
  119.                        ReplyPkt(Packet,DOSTRUE,0L);
  120.                     else
  121.                        ReplyPkt(Packet,DOSFALSE,0L);
  122.                     break;
  123.  
  124.                case ACTION_WRITE:
  125.                     {
  126.                     char *CharPointer;
  127.                    
  128.                     CharPointer=(char *)Packet->dp_Arg2;
  129.                     if (filehan)
  130.                        Write(filehan,CharPointer,(long)Packet->dp_Arg3);
  131.                     filesize+=Packet->dp_Arg3;
  132.                     
  133.                     if (filesize>=1024L*128L)
  134.                        {
  135.                        Close(filehan);
  136.  
  137.                        while (listhan==0)
  138.                              listhan=(BPTR)Open("t:tspool-list",1004L);
  139.                        Seek(listhan,0L,OFFSET_END);
  140.                        Write(listhan,(char*)&filecnt,(long)4L);
  141.                        Close(listhan);
  142.                        listhan=0;
  143.                        
  144.  
  145.                        filesize=0; filecnt++;
  146.                        sprintf(filename,"spool:spool%ld",filecnt);
  147.                        filehan=(BPTR)Open(filename,MODE_NEWFILE);
  148.                        }
  149.                     ReplyPkt(Packet,Packet->dp_Arg3,0L);
  150.                     }
  151.                     break;
  152.  
  153.                case ACTION_END:
  154.                
  155.                     if (filehan)
  156.                        {
  157.                        Close(filehan);
  158.  
  159.                        while (listhan==0)
  160.                              listhan=(BPTR)Open("t:tspool-list",1004L);
  161.                        Seek(listhan,0L,OFFSET_END);
  162.                        Write(listhan,(char*)&filecnt,(long)4L);
  163.                        Close(listhan);
  164.                        listhan=0;
  165.  
  166.  
  167.                        filehan=0;  filesize=0;
  168.                        }
  169.                     ReplyPkt(Packet,DOSTRUE,0L);
  170.                     break;
  171.  
  172.                case ACTION_DIE:             
  173.                     if (filehan) 
  174.                        {
  175.                        Close(filehan);
  176.  
  177.                        while (listhan==0)
  178.                              listhan=(BPTR)Open("t:tspool-list",1004L);
  179.                        Seek(listhan,0L,OFFSET_END);
  180.                        Write(listhan,(char*)&filecnt,(long)4L);
  181.                        Close(listhan);
  182.                        listhan=0;
  183.  
  184.  
  185.                        filehan=0;   filesize=0;
  186.                        }
  187.  
  188.                     if (IsMsgPortEmpty(&MyProcess->pr_MsgPort))
  189.                        {
  190.                        ReplyPkt(Packet,DOSTRUE,0L);
  191.                        UnLoadSeg(DeviceNode->dn_SegList);
  192.                        DeviceNode->dn_SegList=NULL;
  193.                        DeviceNode->dn_Task=NULL;
  194.                        CloseLibrary((struct Library *)DOSBase);
  195.                        return;
  196.                        }
  197.                     ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
  198.                     break;
  199.  
  200.                default:
  201.                     ReplyPkt(Packet,DOSFALSE,ERROR_ACTION_NOT_KNOWN);
  202.                     break;
  203.             }
  204.       }
  205. }
  206.